package cn.fraudmetrix.forseti.biz.service.impl.${basePackage}.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fraudmetrix.forseti.dal.mysql.util.PageParameter;
import cn.fraudmetrix.forseti.dal.mysql.util.Pagination;

import cn.fraudmetrix.forseti.dal.mysql.dto.${basePackage}.${className}SearchDTO;
import cn.fraudmetrix.forseti.dal.mysql.dao.${basePackage}.${className}Dao;
import cn.fraudmetrix.forseti.dal.mysql.object.${basePackage}.${className}DO;
import cn.fraudmetrix.forseti.biz.service.intf.${basePackage}.${className}Service;

/**
* @Author: smili
*/
@Service
public class ${className}ServiceImpl implements ${className}Service {

    @Autowired
    private ${className}Dao ${lowerClassName}Dao;

    @Override
    public void add(${className} param) {

        //TODO设置uuid，gmtCreate等
        ${lowerClassName}Dao.insertSelective(${lowerClassName});
    }

    @Override
    public void delete(${pkType} ${pkName}) {

        ${lowerClassName}Dao.deleteByPrimaryKey(${pkName});
    }

    void delete(Map<String,Object> map){

      ${lowerClassName}Dao.deleteByUpdate(map);
    }

    @Override
    public void update(${className} param) {

        //TODO设置gmtUpdate等
        ${lowerClassName}Dao.updateByPrimaryKeySelective(${lowerClassName});

    }

    @Override
    public void updateSelective(${className} param) {

        //TODO设置gmtUpdate等
        ${lowerClassName}Dao.updateByPrimaryKey(${lowerClassName});

    }

    @Override
    public ${className} selectByPrimaryKey(${pkType} ${pkName}) {

        return ${lowerClassName}Dao.selectByPrimaryKey(${pkName});
    }

    @Override
    public Pagination<${className}> searchForPage(${className}SearchDTO ${lowerClassName}SearchDTO) {

        Pagination<${className}DO> pagination = new Pagination<>();

        PageParameter pageParameter = new PageParameter();
        pageParameter.setCurrentPage(${lowerClassName}SearchDTO.getPageIndex());
        pageParameter.setPageSize(${lowerClassName}SearchDTO.getPageSize());
        ${lowerClassName}SearchDTO.setPage(pageParameter);

        List<${className}DO> ${lowerClassName}List = ${lowerClassName}Dao.selectPage(scoreRuleSearchDTO);

        pagination.setPageIndex(${lowerClassName}SearchDTO.getPageIndex());
        pagination.setPageSize(${lowerClassName}SearchDTO.getPageSize());
        pagination.setResult(${lowerClassName}List);
        pagination.setTotalCount(pageParameter.getTotalCount());
        pagination.setTotalPage(pageParameter.getTotalPage());

        return pagination;
    }

}
